%%%-------------------------------------------------------------------
%%% @author 92913
%%% @copyright (C) 2024, <COMPANY>
%%% @doc
%%% 使用冒泡排序对列表进行排序
%%% @end
%%% Created : 20. 7月 2024 16:07
%%%-------------------------------------------------------------------
-module(d19).
-author("92913").

%% API 使用冒泡排序对列表进行排序
-export([start/0]).

%%冒泡排序
bubble_sort(L) -> bubble_sort(L,len(L)).
bubble_sort(L,1) -> L;
bubble_sort([H|T],N) ->
  Result = bubble_once(H,T),
  io:format("Result is  ~p~n",[Result]),
  bubble_sort(Result,N-1).


bubble_once(H,[]) -> [H];
bubble_once(X,[H|T]) ->
  if X > H ->
    [H|bubble_once(X,T)];
    true ->
      [X|bubble_once(H,T)]
  end.

len([]) -> 0;
len([_|T]) -> 1 + len(T).

start() ->
  bubble_sort([5,3,9,1,6,7,8,2,4,0]).